Cookies =
{
	/* lay cookie */
    getCookie: function (cName) {
        var i, x, y, ARRcookies = document.cookie.split(";");
        for (i = 0; i < ARRcookies.length; i++) {
            x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
            y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
            x = x.replace(/^\s+|\s+$/g, "");
            if (x == cName) {
                return unescape(y);
            }
        }
        return null;
    },

    /* thiet lap - tao moi cookie */
    setCookie: function (cName, cValue, exdays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var cValue1 = escape(cValue) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
        document.cookie = cName + "=" + cValue1;
    },

    /* thiet lap cookie (luu bookmark) tren ban do */
    setCookieBookmark: function (cName, cValue, exdays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        cValue = escape(cValue) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
        var objValueBookmark = this.getCookie("dng_558");
        if (objValueBookmark != null) {
            objValueBookmark = objValueBookmark + "|" + cName + "-" + cValue;
        }
        else objValueBookmark = cName + "-" + cValue;
        document.cookie = "dng_558=" + objValueBookmark;
    },

    /* xoa cookie */
    Delete: function (name) {
        //this.setCookie(name, "", -1);
    	document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    },
    
    /* xoa cookie (bookmark) tren ban do */
    DeleteBookmark: function(indexBookmark)
    {
    	indexBookmark = parseInt(indexBookmark);
		// xoa bookmark tu cookie
		var objBookmark = this.getCookie("dng_558");
    	this.Delete("dng_558");
		var objBookmarks = objBookmark.split('|');
		var i=0;
		for(i=0;i<objBookmarks.length;i++)
		{
			objBookmark = objBookmarks[i].split('-');
			var cName = objBookmark[0];
			var cValue = objBookmark[1] + '-' + objBookmark[2] + '-' + objBookmark[3] + '-' + objBookmark[4];
			if(i != indexBookmark) this.setCookieBookmark(cName, cValue, 365);
		}
    },

    /* kiem tra cookie co ton tai hay ko */
    checkCookie: function (cookieName) {
        var objCookies = getCookie(cookieName);
        if (objCookies != null && objCookies != "") {
            return true;
        }
        else {
            return false;
        }
    }
};
